import * as Koa from 'koa';
import * as Router from 'koa-router';
import * as Logger from 'koa-logger';
import * as path from 'path';

import Static from './static';

let router = new Router();
router.use(async (ctx, next) => {
    try {
        await next();
    } catch (ex) {
        ctx.body = { err: ex.message };
    }
});

const app = new Koa();

app.use(Logger());

Static.init(app);
app.use(router.routes());
app.use(router.allowedMethods());

let port = 1234;
app.listen(port);
console.log('listen on port:', port);
